package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.Bank;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

/**
 * @author Alexander Kotov (kotov.alex.22@gmail.com)
 */
public class BankLoader {
    private Bank bank;

    public BankLoader(final String fileName) throws ClassNotFoundException, IOException, BankLoadException {
        Object object = null;
        try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileName))) {
            object = ois.readObject();
        }
        if (object instanceof Bank) {
            bank = (Bank) object;
        } else {
            throw new BankLoadException("Can't load Bank object");
        }
    }

    public Bank getBank() {
        return bank;
    }

}
